/**
 * @file
 * @auth jinguangguo
 * @date 2016/12/29
 */

import Vue from 'vue';
import tpl from './tpl.html';
import commonService from '../../common/commonService'
import lib from '../../../src/common/lib'
import ActiveSuccess from './ActiveSuccess.vue';
import parseUrl from '../../../grsc-base/util/parseUrl';
import Loading from '../../../grsc-base/component/Loading.vue';


export default Vue.extend({
    name: 'Active',
    template: tpl,
    data(){
        return {
            lib:lib,
            isLoading:false,
            isSuccess:false
        }
    },
    created() {

        if(lib.isMobile() && window.location.href.indexOf('m_active.html') < 0){
            // 移动端跳转
            // window.location.href = 'm_active.html';
            let href = window.location.href;
            window.location.href = href.replace('active.html', 'm_active.html');
            return;
        }

        let query = parseUrl();
        this.userPreRegistrationId = query.userPreRegistrationId;
        this.randomCode = query.randomCode;

        this.activeRegister()
    },
    mounted(){

    },
    components: {
        ActiveSuccess,
        Loading
    },
    methods: {
        activeRegister(){
            this.isLoading = true;
            let param = {
                userPreRegistrationId:this.userPreRegistrationId,
                randomCode:this.randomCode
            };
            commonService.RegisterActive(param).done(rep=>{
                if (rep.code === window.CODE.SUCCESS) {
                    this.isSuccess = true;
                }else{
                    this.isSuccess = false;
                    window.error(rep.msg)
                }
            }).always(rep=>{
                this.isLoading = false
            })
        }
    }
});
